import Vue from "vue";
import Router from "vue-router";

Vue.use(Router);

/* Layout */
import Layout from "@/layout";
import Login from "@/views/login/index";

/**
 * constantRoutes
 * 没有权限要求的基页
 * 所有角色都可以访问
 */
// 常量路由
export const constantRoutes = [
  {
    path: "/",
    component: Layout,
    redirect: "/dashboard",
    children: [
      {
        path: "dashboard",
        name: "dashboard",
        component: () => import("@/views/dashboard/index"),
        meta: {
          title: "数据中心",
          icon: "el-icon-s-home",
        },
      },
    ],
  },
  {
    path: "/login",
    // component: () => import('@/views/login/index'),
    component: Login,
    hidden: true,
  },

  {
    path: "/404",
    component: () => import("@/views/404"),
    hidden: true,
  },
];
// 异步路由
export const asyncRoutes = [
  // {
  //   path: "/userManage",
  //   component: Layout,
  //   redirect: "/UserManage/index",
  //   name: "UserManage",
  //   children: [
  //     {
  //       path: "index",
  //       name: "UserManageCre",
  //       component: () => import("@/views/userManage/index"),
  //       meta: {
  //         title: "用户管理",
  //         icon: "el-icon-user-solid",
  //       },
  //     },
  //   ],
  // },
  // {
  //   path: "/price",
  //   name: "UserPrice",
  //   component: Layout,
  //   children: [
  //     {
  //       path: "index",
  //       name: "Price",
  //       component: () => import("@/views/price/index"),
  //       meta: {
  //         title: "产品管理",
  //         icon: "el-icon-s-order",
  //       },
  //     },
  //   ],
  // },
  // {
  //   path: "/statistics",
  //   name: "StatisticsManage",
  //   component: Layout,
  //   children: [
  //     {
  //       path: "index",
  //       name: "Statistics",
  //       component: () => import("@/views/statistics/index"),
  //       meta: {
  //         title: "统计管理",
  //         icon: "el-icon-s-help",
  //       },
  //     },
  //   ],
  // },
  // {
  //   path: "/totalSearch",
  //   component: Layout,
  //   name: "Total",
  //   children: [
  //     {
  //       path: "index",
  //       name: "totalSearch",
  //       component: () => import("@/views/totalSearch/index"),
  //       meta: {
  //         title: "总量查询",
  //         icon: "el-icon-search",
  //       },
  //     },
  //   ],
  // },
  // {
  //   path: "/MyBlance",
  //   component: Layout,
  //   redirect: "/MyBlance/index",
  //   name: "MyBlance",
  //   meta: {
  //     title: "我的账单",
  //     icon: "el-icon-document",
  //   },
  //   children: [
  //     {
  //       path: "index",
  //       name: "APICdr",
  //       component: () => import("@/views/MyBlance/index"),
  //       meta: {
  //         title: "余额明细",
  //         icon: "el-icon-s-finance",
  //       },
  //     },
  //   ],
  // },
  {
    path: "/accountRecharge",
    component: Layout,
    redirect: "/accountRecharge/index",
    name: "Recharge",
    meta: {
      title: "语音总裁卫士",
      icon: "el-icon-suitcase-1",
    },
    children: [
      {
        path: "productOverview",
        name: "ProductOverview",
        component: () =>
          import("@/views/accountRecharge/productOverview/index"),
        meta: {
          title: "产品概览",
          icon: "el-icon-medal",
        },
      },
      {
        path: "index",
        name: "AccountRecharge",
        component: () => import("@/views/accountRecharge/index"),
        meta: {
          title: "检测记录",
          icon: "el-icon-medal",
        },
      },
      {
        path: "rechargeDetails",
        name: "RechargeDetails",
        component: () =>
          import("@/views/accountRecharge/rechargeDetails/index"),
        meta: {
          title: "ip白名单",
          icon: "el-icon-c-scale-to-original",
        },
      },
      {
        path: "rechargeRecord",
        name: "RechargeRecord",
        component: () => import("@/views/accountRecharge/rechargeRecord/index"),
        meta: {
          title: "ip加白",
          icon: "el-icon-s-operation",
        },
      },
      {
        path: "ruleConfiguration",
        name: "RuleConfiguration",
        component: () =>
          import("@/views/accountRecharge/ruleConfiguration/index"),
        meta: {
          title: "规则配置",
          icon: "el-icon-notebook-1",
        },
      },
      {
        path: "dataStatistics",
        name: "DataStatistics",
        component: () => import("@/views/accountRecharge/dataStatistics/index"),
        meta: {
          title: "数据统计",
          icon: "el-icon-data-analysis",
        },
      },
      {
        path: "Recharge",
        name: "Recharge",
        component: () => import("@/views/phone/index"),
        meta: {
          title: "号码配置",
          icon: "el-icon-phone-outline",
        },
      },
    ],
  },
  // {
  //   path: "/auditRecharge",
  //   component: Layout,
  //   redirect: "/auditRecharge/index",
  //   name: "AuditManagement",
  //   meta: {
  //     title: "审核管理",
  //     icon: "el-icon-suitcase-1",
  //   },
  //   children: [
  //     {
  //       path: "index",
  //       name: "AuditRecharge",
  //       component: () => import("@/views/auditRecharge/index"),
  //       meta: {
  //         title: "充值审核",
  //         icon: "el-icon-s-claim",
  //       },
  //     },
  //   ],
  // },
  // {
  //   path: "/ticketsManage",
  //   component: Layout,
  //   redirect: "/ticketsManage/index",
  //   name: "Ticket",
  //   meta: {
  //     title: "工单管理",
  //     icon: "el-icon-finished",
  //   },
  //   children: [
  //     {
  //       path: "index",
  //       name: "TicketsManage",
  //       component: () => import("@/views/ticketsManage/index"),
  //       meta: {
  //         title: "提交工单",
  //         icon: "el-icon-finished",
  //       },
  //     },
  //     {
  //       path: "ticketsDetails",
  //       name: "TicketsDetails",
  //       component: () => import("@/views/ticketsManage/ticketsDetails/index"),
  //       meta: {
  //         title: "工单记录",
  //         icon: "el-icon-c-scale-to-original",
  //       },
  //     },
  //     // , {
  //     //   path: 'ticketsRecord',
  //     //   name: 'TicketsRecord',
  //     //   component: () => import('@/views/ticketsManage/ticketsRecord/index'),
  //     //   meta: {
  //     //     title: '处理记录',
  //     //     icon: 'el-icon-s-operation'
  //     //   }
  //     // }
  //   ],
  // },
  // {
  //   path: "/auditTickets",
  //   component: Layout,
  //   redirect: "/auditTickets/index",
  //   name: "AuditTickets",
  //   meta: {
  //     title: "工单处理",
  //     icon: "el-icon-finished",
  //   },
  //   children: [
  //     {
  //       path: "index",
  //       name: "AuditTickets",
  //       component: () => import("@/views/auditTickets/index"),
  //       meta: {
  //         title: "工单处理",
  //         icon: "el-icon-edit-outline",
  //       },
  //     },
  //   ],
  // },
  // {
  //   path: "/API",
  //   component: Layout,
  //   redirect: "/API/index",
  //   name: "API",
  //   meta: {
  //     title: "余额提醒",
  //     icon: "el-icon-document",
  //   },
  //   children: [
  //     {
  //       path: "index",
  //       name: "APICdr",
  //       component: () => import("@/views/API/index"),
  //       meta: {
  //         title: "提醒配置",
  //         icon: "el-icon-document",
  //       },
  //     },
  //   ],
  // },
];
// 任意路由 当路径出现错误的时候,重定向到404
export const anyRoutes =
  // 404 页面必须放在末尾！！！
  {
    path: "*",
    redirect: "/404",
    hidden: true,
  };

const createRouter = () =>
  new Router({
    mode: "hash", // require service support
    scrollBehavior: () => ({
      y: 0,
    }),
    routes: constantRoutes,
  });

const router = createRouter();

// 重置路由
export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher; // 重新设置路由的可匹配路径
}

export default router;
